package com.example.travel_front.Activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.example.travel_front.Fragment.CaregiverFragment;
import com.example.travel_front.Fragment.ChatFragment;
import com.example.travel_front.Fragment.HomeFragment;
import com.example.travel_front.Fragment.IndexFragment;
import com.example.travel_front.Fragment.MapFragment;
import com.example.travel_front.Fragment.NewsFragment;
import com.example.travel_front.Fragment.UserFragment;
import com.example.travel_front.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class HomeActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation);
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
        bottomNavigationView.setOnItemSelectedListener(item -> {
            Fragment selectedFragment = null;
            int itemId = item.getItemId();

            if (itemId == R.id.navigation_home) {
                selectedFragment = new IndexFragment();
            } else if (itemId == R.id.navigation_caregiver) {
                selectedFragment = new CaregiverFragment();
            } else if (itemId == R.id.navigation_message) {
                selectedFragment = new ChatFragment();
            } else if (itemId == R.id.navigation_news) {
                selectedFragment = new NewsFragment();
            }
            else if (itemId == R.id.navigation_user) {
                selectedFragment = new UserFragment();
            }

            if (selectedFragment != null) {
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, selectedFragment).commit();
            }

            return true;
        });

        // 设置默认显示的 Fragment
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();
            bottomNavigationView.setSelectedItemId(R.id.navigation_home);
        }
    }



}
